package com.yqz.sys.service.impl;

import com.yqz.common.Constant;
import com.yqz.common.Result;
import com.yqz.common.base.Form;
import com.yqz.common.base.Query;
import com.yqz.common.base.service.impl.BaseServiceImpl;
import com.yqz.common.util.WebUtil;
import com.yqz.sys.form.CompDepartForm;
import com.yqz.sys.mapper.CompDepartMapper;
import com.yqz.sys.query.CompDepartQuery;
import com.yqz.sys.service.CompDepartService;
import com.yqz.sys.vo.CompDepartVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CompDepartServiceImpl extends BaseServiceImpl implements CompDepartService {

    @Autowired
    private CompDepartMapper departMapper;

    public CompDepartServiceImpl(CompDepartMapper departMapper) {
        super(departMapper);
    }

    @Override
    public Result queryAll(CompDepartQuery query) {
        query.setCompId(WebUtil.getCurrentCompUser().getCompId());
        List<CompDepartVO> compDeparts = departMapper.findByAll(query);
        return new Result(compDeparts);
    }

    @Override
    public Result queryPage(Query query) {
      CompDepartQuery compDepartQuery = (CompDepartQuery) query;
      compDepartQuery.setCompId(WebUtil.getCurrentCompUser().getCompId());
      return super.queryPage(compDepartQuery);
    }

    @Override
    public Result add(Form form) {
        CompDepartForm compDepartForm = (CompDepartForm) form;
        compDepartForm.setCompId(WebUtil.getCurrentCompUser().getCompId());
        compDepartForm.setFlag(Constant.DEPT_FLAG_VALID);
        return super.add(form);
    }

}
